package vn.sms.lazylove;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.WindowManager.LayoutParams;

public class AlertDemo extends DialogFragment {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		/**
		 * Turn Screen On and Unlock the keypad when this alert dialog is
		 * displayed
		 */
		getActivity().getWindow().addFlags(
				LayoutParams.FLAG_TURN_SCREEN_ON
						| LayoutParams.FLAG_DISMISS_KEYGUARD);

		/** Creating a alert dialog builder */
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

		/** Setting title for the alert dialog */
		builder.setTitle("Lazy Love");

		/** Setting the content for the alert dialog */
		builder.setMessage("Messages send successful in LazyLove!");

		/** Defining an OK button event listener */
		builder.setPositiveButton("OK", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				/** Exit application on click OK */
				Intent _i = new Intent(getActivity().getApplicationContext(),
						SendSMSActivity.class)
						.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
								| Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startActivity(_i);
				getActivity().finish();
			}
		});

		/** Creating the alert dialog window */
		return builder.create();
	}

	/** The application should be exit, if the user presses the back button */
	@Override
	public void onDestroy() {
		super.onDestroy();
		getActivity().finish();
	}

}
